
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName()
            + ":" + request.getServerPort() + path + "/";
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link href="<%=basePath%>Css/Content.css" rel="stylesheet" type="text/css" />
    <!-- Bootstrap Core CSS -->
    <link href="<%=basePath%>Css/bootstrap.min.css" rel="stylesheet" />
    <link href="<%=basePath%>Css/button.css" rel="stylesheet" type="text/css" />
    <link href="<%=basePath%>Css/dataTables.bootstrap.css" rel="stylesheet" />
    <link href="<%=basePath%>Css/metisMenu.min.css" rel="stylesheet" />
    <!-- 引入js文件 -->
    <!-- jQuery -->
    <script src="<%=basePath%>js/jquery-1.11.3.min.js"></script>
    <!-- Bootstrap Core JavaScript -->
    <script src="<%=basePath%>js/bootstrap.min.js"></script>
    <!-- Metis Menu Plugin JavaScript -->
    <script src="<%=basePath%>js/metisMenu.min.js"></script>
    <!-- DataTables JavaScript -->
    <script src="<%=basePath%>js/jquery.dataTables.min.js"></script>
    <script src="<%=basePath%>js/dataTables.bootstrap.min.js"></script>

    <!-- Custom Theme JavaScript -->
    <script src="<%=basePath%>js/sb-admin-2.js"></script>
    <script type="text/javascript">




        function deleteGrade(gradesId) {
            if(confirm('确实要删除该信息吗?')){
                $.post("<%=basePath%>/deleteGrade.action",{"gradesId":gradesId},
                    function (data) {
                        if (data == "OK"){
                            alert("删除成功！");
                            window.location.reload();
                        }
                        else {
                            alert("删除失败！");
                            window.location.reload();
                        }
                    }
                )
            }
        }
        //此js用于将数据填入修改模态框中作为初始值
        function editGrade(gradesId) {
            $.ajax({
                type:"get",
                url:"<%=basePath%>/findGradeBygradesId.action",
                data:{"gradesId":gradesId},
                success:function (data) {
                    console.log(data)
                    $("#gradesId").val(data.gradesId);
                    $("#username").val(data.username);
                    $("#math_grades").val(data.math_grades);
                    $("#english_grades").val(data.english_grades);
                    $("#chinese_grades").val(data.chinese_grades);

                }
            });
        }
    function updateGrade() {
        $.post("<%=basePath%>/updateGrade.action  ",$("#edit_loan_form").serialize(),function (data) {
            if(data =="OK"){
                alert("更新成功！");
                window.location.reload();
            }else{
                alert("更新失败！");
                window.location.reload();
            }
        })
    }


    </script>
</head>
<body>





<div class="panel panel-primary">
    <div class="panel-body">
    <table class="table table-striped">

        <thead>   <tr >
            <th>成绩编号</th><th>学生名</th><th>数学成绩</th><th>英语成绩</th><th>语文成绩</th><th>操作</th>
        </tr>
        </thead>
        <tbody>

        <c:forEach items="${Grades}" var="grade">

            <tr >
                <td>
                    ${grade.gradesId}
                </td>
                <td>${grade.username}</td>
                <td>${grade.math_grades}</td>
                <td>${grade.english_grades}</td>
                <td>${grade.chinese_grades}</td>
                <td>
                    &nbsp;<a class="button button-box button-small button-longshadow-right button-caution" data-toggle="modal" data-target="#loanEditDialog" onclick="editGrade(${grade.gradesId})">修改</a></td>

            </tr>

        </c:forEach>
        </tbody>
    </table>
    </div>
</div>

<div class="modal fade" id="loanEditDialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">修改成绩信息</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" id="edit_loan_form">
                    <input type="hidden" id="edit_The_loan_id" name="The_loan_id"/>
                    <div class="form-group"  hidden="hidden">
                        <label for="gradesId" class="col-sm-2 control-label" >
                            成绩编号
                        </label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control"id="gradesId" placeholder="成绩编号" name="gradesId" hidden="hidden">
                        </div>
                    </div>

                    <div class="form-group"  hidden="hidden">
                        <label for="username" class="col-sm-2 control-label">
                            学生名
                        </label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="username" placeholder="学生" name="username" hidden="hidden">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="math_grades" class="col-sm-2 control-label">
                            数学成绩
                        </label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="math_grades" placeholder="数学成绩" name="math_grades">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="english_grades" class="col-sm-2 control-label">
                            英语成绩
                        </label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="english_grades" placeholder="英语成绩" name="english_grades">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="chinese_grades" class="col-sm-2 control-label">
                            语文成绩
                        </label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="chinese_grades" placeholder="语文成绩" name="chinese_grades">
                        </div>
                    </div>

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="updateGrade()">保存修改</button>
            </div>
        </div>
    </div>
    <%--模态框结束--%>
</div>
</body>
</html>

